package mr.zhang.service.impl;

import mr.zhang.dao.TestMyBaTisDao;
import mr.zhang.dao.domain.Merchant;
import mr.zhang.service.TestMyBatisService;
import mr.zhang.util.PageModelMerChant;

import java.util.List;



public class TestMyBatisServiceImpl implements TestMyBatisService {
	
	private TestMyBaTisDao testMyBatisDao;
	
	

	public TestMyBaTisDao getTestMyBatisDao() {
		return testMyBatisDao;
	}

	public void setTestMyBatisDao(TestMyBaTisDao testMyBatisDao) {
		this.testMyBatisDao = testMyBatisDao;
	}

	@Override
	public void saveMerchant(Merchant merchant) {
		// TODO Auto-generated method stub
		
		this.testMyBatisDao.saveMerchant(merchant);

	}

	@Override
	public void deleteMerchant(int id) {
		// TODO Auto-generated method stub
		
		this.testMyBatisDao.deleteMerchant(id);

	}

	@Override
	public void updateMerchant(Merchant merchant) {
		// TODO Auto-generated method stub
		
		this.testMyBatisDao.updateMerchant(merchant);

	}

	@Override
	public Merchant queryMerchantById(int id) {
		// TODO Auto-generated method stub
		return this.testMyBatisDao.queryMerchantById(id);
	}

	@Override
	public PageModelMerChant queryMerchant(int offset, int pagesize) {
		// TODO Auto-generated method stub
		 List<Merchant> list = this.testMyBatisDao.queryMerchant( offset,  pagesize);
		 
		 int total = this.queryMerchantCount();
		 
		 int totalpage = 0;
		 
		 if (total % pagesize == 0) {

				totalpage = total / pagesize;

			} else {

				totalpage = (total / pagesize) + 1;

			}
		 
		 PageModelMerChant pageModelMerChant = new PageModelMerChant();
		 
		 pageModelMerChant.setList(list);
		 
		 pageModelMerChant.setTotal(totalpage);
		 
		 pageModelMerChant.setTotalpage(totalpage);
		 
		 return pageModelMerChant;
	}

	@Override
	public int queryMerchantCount() {
		// TODO Auto-generated method stub
		return this.testMyBatisDao.queryMerchantCount();
	}

	@Override
	public List<Merchant> queryMerchantall() {
		// TODO Auto-generated method stub
		return this.testMyBatisDao.queryMerchantall();
	}

}
